
GO

/****** Object:  View [dbo].[balades_VisitAdmin]    Script Date: 09/21/2011 20:29:26 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[balades_VisitAdmin]'))
DROP VIEW [dbo].[balades_VisitAdmin]
GO

/****** Object:  View [dbo].[balades_VisitDashboard]    Script Date: 09/21/2011 20:29:26 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[balades_VisitDashboard]'))
DROP VIEW [dbo].[balades_VisitDashboard]
GO


GO

/****** Object:  View [dbo].[balades_VisitAdmin]    Script Date: 09/21/2011 20:29:32 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

/****** Object:  View [dbo].[balades_VisitAdmin]    Script Date: 09/03/2011 08:17:33 ******/
CREATE VIEW [dbo].[balades_VisitAdmin]
AS
SELECT     dbo.balades_Visit.VisitID, dbo.balades_Visit.Title, dbo.balades_Visit.PlaceCategoryID, dbo.balades_Visit.MarketingCategoryID, dbo.balades_Visit.UrlName, 
                      dbo.balades_Visit.SumUp, dbo.balades_Visit.Text, dbo.balades_Visit.CreationDate, dbo.balades_Visit.Latitude, dbo.balades_Visit.Longitude, 
                      dbo.balades_Visit.Visible, ISNULL(dbo.balades_VisitQuality.SumUp, 0) AS QualitySumUp, ISNULL(dbo.balades_VisitQuality.Text, 0) AS QualityText, 
                      ISNULL(dbo.balades_VisitQuality.Gps, 0) AS QualityGps, ISNULL(dbo.balades_VisitQuality.Pictures, 0) AS QualityPictures, 
                      ISNULL(dbo.balades_VisitQuality.Informations, 0) AS QualityInformations, ISNULL(dbo.balades_VisitQuality.Categories, 0) AS QualityCategories
FROM         dbo.balades_Visit LEFT OUTER JOIN
                      dbo.balades_VisitQuality ON dbo.balades_Visit.VisitID = dbo.balades_VisitQuality.VisitID

GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[27] 4[30] 2[25] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "balades_Visit (dbo)"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 123
               Right = 238
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "balades_VisitQuality (dbo)"
            Begin Extent = 
               Top = 6
               Left = 276
               Bottom = 123
               Right = 476
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 18
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 2280
         Table = 1665
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'balades_VisitAdmin'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'balades_VisitAdmin'
GO

/****** Object:  View [dbo].[balades_VisitDashboard]    Script Date: 09/21/2011 20:29:32 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

/****** Object:  View [dbo].[balades_VisitDashboard]    Script Date: 09/03/2011 08:17:59 ******/
CREATE VIEW [dbo].[balades_VisitDashboard]
AS
SELECT     dbo.balades_Visit.VisitID, dbo.balades_Visit.Title, ISNULL(dbo.balades_VisitQuality.SumUp, 0) AS QualitySumUp, ISNULL(dbo.balades_VisitQuality.Text, 0) 
                      AS QualityText, ISNULL(dbo.balades_VisitQuality.Gps, 0) AS QualityGps, ISNULL(dbo.balades_VisitQuality.Pictures, 0) AS QualityPictures, 
                      ISNULL(dbo.balades_VisitQuality.Informations, 0) AS QualityInformations, ISNULL(dbo.balades_VisitQuality.Categories, 0) AS QualityCategories
FROM         dbo.balades_Visit LEFT OUTER JOIN
                      dbo.balades_VisitQuality ON dbo.balades_Visit.VisitID = dbo.balades_VisitQuality.VisitID

GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[34] 4[29] 2[12] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "balades_Visit (dbo)"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 123
               Right = 238
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "balades_VisitQuality (dbo)"
            Begin Extent = 
               Top = 6
               Left = 276
               Bottom = 123
               Right = 476
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1665
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'balades_VisitDashboard'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'balades_VisitDashboard'
GO




/****** Object:  StoredProcedure [dbo].[balades_InsertVisit]    Script Date: 09/03/2011 08:27:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[balades_InsertVisit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[balades_InsertVisit]
GO

/****** Object:  StoredProcedure [dbo].[balades_InsertVisit]    Script Date: 09/03/2011 08:27:52 ******/
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[balades_InsertVisit]
@PlaceCategoryID int,
@MarketingCategoryID int,
@Title varchar (100) ,
@UrlName varchar (60),
@SumUp text,
@Text text,
@Latitude float,
@Longitude float,
@Visible bit
AS
BEGIN
	declare @VisitId int
	declare @CreationDate datetime
	
	set  @CreationDate = null
	
	if @Visible = 1
		set @CreationDate = GETDATE()
	
	insert balades_Visit(PlaceCategoryID, MarketingCategoryID
	, Title, UrlName, SumUp, [Text], Latitude, Longitude, Visible, CreationDate)
	values(@PlaceCategoryID ,@MarketingCategoryID ,@Title 
	,@UrlName ,@SumUp ,@Text ,@Latitude ,@Longitude ,@Visible,@CreationDate )

	select @VisitId = MAX(@@Identity)
		
	return @VisitId
	
END
GO

/****** Object:  StoredProcedure [dbo].[balades_InsertVisitInformation]    Script Date: 09/03/2011 08:28:00 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[balades_InsertVisitInformation]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[balades_InsertVisitInformation]
GO

/****** Object:  StoredProcedure [dbo].[balades_InsertVisitInformation]    Script Date: 09/03/2011 08:28:00 ******/
CREATE PROCEDURE [dbo].[balades_InsertVisitInformation]
@InformationTypeID int ,
@VisitID int ,
@Text varchar(100) ,
@Rank int 
AS
BEGIN
	
	declare @InformationID int
	
	insert balades_Information(InformationTypeID,VisitID,[Rank],[Text])
	values(@InformationTypeID,@VisitID,@Rank, @Text )
	
	select @InformationID = MAX(@@Identity)
	
	return @InformationID
END
GO

/****** Object:  StoredProcedure [dbo].[balades_InsertVisitPicture]    Script Date: 09/03/2011 08:28:13 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[balades_InsertVisitPicture]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[balades_InsertVisitPicture]
GO

/****** Object:  StoredProcedure [dbo].[balades_InsertVisitPicture]    Script Date: 09/03/2011 08:28:13 ******/
CREATE PROCEDURE [dbo].[balades_InsertVisitPicture]
@PictureTypeID int ,
@VisitID int ,
@Title varchar(50) ,
@Text varchar(100) ,
@Url varchar(100) ,
@Rank int 
AS
BEGIN
	
	declare @PictureId int
	
	insert balades_Picture(PictureTypeID,VisitID,[Rank],[Text],Title,Url)
	values(@PictureTypeID,@VisitID,@Rank, @Text, @Title,@Url )
	
	select @PictureId = MAX(@@Identity)
	
	return @PictureId
END
GO

/****** Object:  StoredProcedure [dbo].[balades_UpdateVisit]    Script Date: 09/03/2011 08:28:19 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[balades_UpdateVisit]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[balades_UpdateVisit]
GO

/****** Object:  StoredProcedure [dbo].[balades_UpdateVisit]    Script Date: 09/03/2011 08:28:19 ******/
CREATE PROCEDURE [dbo].[balades_UpdateVisit]
@VisitId int,
@PlaceCategoryID int,
@MarketingCategoryID int,
@Title varchar (100) ,
@UrlName varchar (60),
@SumUp text,
@Text text,
@Latitude float,
@Longitude float,
@Visible bit
AS
BEGIN
	
	declare @CreationDate datetime
	
	if @Visible = 0
	begin
		set @CreationDate = null
	end
	else
	begin
		select @CreationDate = CreationDate
		from balades_Visit
		where balades_Visit.VisitId = @VisitId	
		
		if @CreationDate is null
			set @CreationDate = GETDATE()
	end
	
	update balades_Visit
	set PlaceCategoryID =@PlaceCategoryID
	, MarketingCategoryID =@MarketingCategoryID
	, Title =@Title
	, UrlName =@UrlName
	, SumUp =@SumUp
	, [Text] =@Text
	, Latitude  =@Latitude
	, Longitude =@Longitude
	, Visible =@Visible
	, CreationDate = @CreationDate
	where balades_Visit.VisitId = @VisitId	
	
	
END
GO

/****** Object:  StoredProcedure [dbo].[balades_UpdateVisit]    Script Date: 09/03/2011 08:28:19 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[balades_UpdateVisitQuality]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].balades_UpdateVisitQuality
GO

/****** Object:  StoredProcedure [dbo].[balades_UpdateVisit]    Script Date: 09/03/2011 08:28:19 ******/
CREATE PROCEDURE [dbo].balades_UpdateVisitQuality
@VisitId int,
@SumUp bit,
@Text bit,
@Gps bit,
@Pictures bit,
@Informations bit,
@Categories bit
AS
BEGIN
	
	delete balades_VisitQuality
	where VisitID = @VisitId
	
	insert balades_VisitQuality(VisitId ,SumUp ,[Text] ,
		Gps ,Pictures ,Informations ,Categories )
	values(@VisitId ,	@SumUp ,	@Text ,
	@Gps ,	@Pictures ,	@Informations ,	@Categories )
	
	
END
GO

/****** Object:  StoredProcedure [dbo].[balades_DeleteVisitInformations]    Script Date: 09/03/2011 08:28:36 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[balades_DeleteVisitInformations]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[balades_DeleteVisitInformations]
GO

/****** Object:  StoredProcedure [dbo].[balades_DeleteVisitInformations]    Script Date: 09/03/2011 08:28:36 ******/
CREATE PROCEDURE [dbo].[balades_DeleteVisitInformations]
@VisitId int
AS
BEGIN
	
	delete balades_Information
	where VisitID = @VisitId
	
END
GO

/****** Object:  StoredProcedure [dbo].[balades_DeleteVisitPictures]    Script Date: 09/03/2011 08:28:41 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[balades_DeleteVisitPictures]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[balades_DeleteVisitPictures]
GO

/****** Object:  StoredProcedure [dbo].[balades_DeleteVisitPictures]    Script Date: 09/03/2011 08:28:41 ******/
CREATE PROCEDURE [dbo].[balades_DeleteVisitPictures]
@VisitId int
AS
BEGIN
	
	delete balades_Picture
	where VisitID = @VisitId
	
END

GO



